package com.sls.game.dao.wogreat.impl;

import java.util.List;

import org.springframework.stereotype.Repository;

import com.sls.game.dao.impl.SuperDAO;
import com.sls.game.dao.wogreat.WogreatAccountDAO;
import com.sls.game.page.Pagination;
import com.sls.game.pojo.wogreat.WogreatAccountType;

@Repository("wogreatAccountDAO")
public class WogreatAccountDAOImpl extends SuperDAO<WogreatAccountType>
		implements WogreatAccountDAO {

	@Override
	public void insertAccount(WogreatAccountType account) {
		this.getSqlSession().insert(
				"mybatis.xml.WogreatAccountTypeMapper.insert", account);

	}

	@Override
	public List<WogreatAccountType> queryByProIdAndAccountName(
			WogreatAccountType account) {
		return this
				.getSqlSession()
				.selectList(
						"mybatis.xml.WogreatAccountTypeMapper.queryByProIdAndAccountName",
						account);
	}

	@Override
	public Pagination<WogreatAccountType> queryPage(WogreatAccountType account) {
		Pagination<WogreatAccountType> paginationList = null;
		Integer rowCount = queryRowCount(account);
		account.calculate();
		List<WogreatAccountType> list = queryAccountList(account);
		paginationList = this.queryPagination(rowCount, list, account);
		return paginationList;
	}

	/**
	 * 查询记录总数
	 * 
	 * @param enLinkGoodsInfo
	 * @return
	 */
	private Integer queryRowCount(WogreatAccountType account) {
		Integer rowCount = this.getSqlSession().selectOne(
				"mybatis.xml.WogreatAccountTypeMapper.queryRowCount", account);
		return rowCount;
	}

	/**
	 * 记录结果集list
	 * 
	 * @param enLinkGoodsInfo
	 * @return
	 */
	private List<WogreatAccountType> queryAccountList(WogreatAccountType account) {
		List<WogreatAccountType> list = this.getSqlSession().selectList(
				"mybatis.xml.WogreatAccountTypeMapper.queryWogreatAccInfoList",
				account);
		return list;
	}

	@Override
	public List<String> queryAccNameByProductId(String productId) {
		List<String> list = this.getSqlSession().selectList(
				"mybatis.xml.WogreatAccountTypeMapper.queryAccNameByProductId",
				productId);
		return list;
	}

	@Override
	public void deleteByProductId(String productId) {
		this.getSqlSession().delete(
				"mybatis.xml.WogreatAccountTypeMapper.deleteByProductId",
				productId);
	}

}
